{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "             low  close  limit_up  limit_down  high  open\ndate                                                     \n2021-03-10  4.08   4.09      4.54        3.72  4.26  4.20\n2021-03-11  4.03   4.21      4.50        3.68  4.30  4.06\n2021-03-12  4.16   4.42      4.63        3.79  4.49  4.18\n2021-03-15  4.39   4.86      4.86        3.98  4.86  4.41\n2021-03-16  5.35   5.35      5.35        4.37  5.35  5.35\n2021-03-17  5.89   5.89      5.89        4.82  5.89  5.89\n2021-03-18  6.02   6.48      6.48        5.30  6.48  6.30\n2021-03-19  6.14   6.87      7.13        5.83  7.12  6.14\n2021-03-22  6.54   7.56      7.56        6.18  7.56  6.76\n2021-03-23  7.18   8.32      8.32        6.80  8.32  7.86",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>low</th>\n      <th>close</th>\n      <th>limit_up</th>\n      <th>limit_down</th>\n      <th>high</th>\n      <th>open</th>\n    </tr>\n    <tr>\n      <th>date</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2021-03-10</th>\n      <td>4.08</td>\n      <td>4.09</td>\n      <td>4.54</td>\n      <td>3.72</td>\n      <td>4.26</td>\n      <td>4.20</td>\n    </tr>\n    <tr>\n      <th>2021-03-11</th>\n      <td>4.03</td>\n      <td>4.21</td>\n      <td>4.50</td>\n      <td>3.68</td>\n      <td>4.30</td>\n      <td>4.06</td>\n    </tr>\n    <tr>\n      <th>2021-03-12</th>\n      <td>4.16</td>\n      <td>4.42</td>\n      <td>4.63</td>\n      <td>3.79</td>\n      <td>4.49</td>\n      <td>4.18</td>\n    </tr>\n    <tr>\n      <th>2021-03-15</th>\n      <td>4.39</td>\n      <td>4.86</td>\n      <td>4.86</td>\n      <td>3.98</td>\n      <td>4.86</td>\n      <td>4.41</td>\n    </tr>\n    <tr>\n      <th>2021-03-16</th>\n      <td>5.35</td>\n      <td>5.35</td>\n      <td>5.35</td>\n      <td>4.37</td>\n      <td>5.35</td>\n      <td>5.35</td>\n    </tr>\n    <tr>\n      <th>2021-03-17</th>\n      <td>5.89</td>\n      <td>5.89</td>\n      <td>5.89</td>\n      <td>4.82</td>\n      <td>5.89</td>\n      <td>5.89</td>\n    </tr>\n    <tr>\n      <th>2021-03-18</th>\n      <td>6.02</td>\n      <td>6.48</td>\n      <td>6.48</td>\n      <td>5.30</td>\n      <td>6.48</td>\n      <td>6.30</td>\n    </tr>\n    <tr>\n      <th>2021-03-19</th>\n      <td>6.14</td>\n      <td>6.87</td>\n      <td>7.13</td>\n      <td>5.83</td>\n      <td>7.12</td>\n      <td>6.14</td>\n    </tr>\n    <tr>\n      <th>2021-03-22</th>\n      <td>6.54</td>\n      <td>7.56</td>\n      <td>7.56</td>\n      <td>6.18</td>\n      <td>7.56</td>\n      <td>6.76</td>\n    </tr>\n    <tr>\n      <th>2021-03-23</th>\n      <td>7.18</td>\n      <td>8.32</td>\n      <td>8.32</td>\n      <td>6.80</td>\n      <td>8.32</td>\n      <td>7.86</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "output_type": "execute_result",
     "execution_count": 24
    }
   ],
   "source": [
    "\n",
    "stock_price=pd.read_csv(filepath_or_buffer='test1.csv',sep=',',index_col=0)\n",
    "stock_price=stock_price.drop(labels=['num_trades','total_turnover','volume'],axis=1,)\n",
    "stock_price.head(10)\n",
    "\n",
    "\n",
    "start_index=0\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "outputs": [
    {
     "data": {
      "text/plain": "             low  close  limit_up  limit_down  high  open  limit_line\ndate                                                                 \n2021-03-10  4.08   4.09      4.54        3.72  4.26  4.20           0\n2021-03-11  4.03   4.21      4.50        3.68  4.30  4.06           0\n2021-03-12  4.16   4.42      4.63        3.79  4.49  4.18           0\n2021-03-15  4.39   4.86      4.86        3.98  4.86  4.41           0\n2021-03-16  5.35   5.35      5.35        4.37  5.35  5.35           1\n2021-03-17  5.89   5.89      5.89        4.82  5.89  5.89           1\n2021-03-18  6.02   6.48      6.48        5.30  6.48  6.30           0\n2021-03-19  6.14   6.87      7.13        5.83  7.12  6.14           0\n2021-03-22  6.54   7.56      7.56        6.18  7.56  6.76           0\n2021-03-23  7.18   8.32      8.32        6.80  8.32  7.86           0",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>low</th>\n      <th>close</th>\n      <th>limit_up</th>\n      <th>limit_down</th>\n      <th>high</th>\n      <th>open</th>\n      <th>limit_line</th>\n    </tr>\n    <tr>\n      <th>date</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2021-03-10</th>\n      <td>4.08</td>\n      <td>4.09</td>\n      <td>4.54</td>\n      <td>3.72</td>\n      <td>4.26</td>\n      <td>4.20</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2021-03-11</th>\n      <td>4.03</td>\n      <td>4.21</td>\n      <td>4.50</td>\n      <td>3.68</td>\n      <td>4.30</td>\n      <td>4.06</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2021-03-12</th>\n      <td>4.16</td>\n      <td>4.42</td>\n      <td>4.63</td>\n      <td>3.79</td>\n      <td>4.49</td>\n      <td>4.18</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2021-03-15</th>\n      <td>4.39</td>\n      <td>4.86</td>\n      <td>4.86</td>\n      <td>3.98</td>\n      <td>4.86</td>\n      <td>4.41</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2021-03-16</th>\n      <td>5.35</td>\n      <td>5.35</td>\n      <td>5.35</td>\n      <td>4.37</td>\n      <td>5.35</td>\n      <td>5.35</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>2021-03-17</th>\n      <td>5.89</td>\n      <td>5.89</td>\n      <td>5.89</td>\n      <td>4.82</td>\n      <td>5.89</td>\n      <td>5.89</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>2021-03-18</th>\n      <td>6.02</td>\n      <td>6.48</td>\n      <td>6.48</td>\n      <td>5.30</td>\n      <td>6.48</td>\n      <td>6.30</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2021-03-19</th>\n      <td>6.14</td>\n      <td>6.87</td>\n      <td>7.13</td>\n      <td>5.83</td>\n      <td>7.12</td>\n      <td>6.14</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2021-03-22</th>\n      <td>6.54</td>\n      <td>7.56</td>\n      <td>7.56</td>\n      <td>6.18</td>\n      <td>7.56</td>\n      <td>6.76</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2021-03-23</th>\n      <td>7.18</td>\n      <td>8.32</td>\n      <td>8.32</td>\n      <td>6.80</td>\n      <td>8.32</td>\n      <td>7.86</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "output_type": "execute_result",
     "execution_count": 26
    }
   ],
   "source": [
    "stock_price['limit_line']=0\n",
    "\n",
    "# 看看是否一字涨停low=limit_up,\n",
    "stock_price.loc[stock_price['low']==stock_price['limit_up'],'limit_line']=1\n",
    "\n",
    "# 一字跌停,limit_down=high\n",
    "stock_price.loc[stock_price['high']==stock_price['limit_down'],'limit_line']=-1\n",
    "stock_price.head(10)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "outputs": [],
   "source": [
    "# 找到长度\n",
    "index_len=stock_price.shape[0]\n",
    "\n",
    "range_now=(60 if index_len>60 else index_len)\n",
    "range_now"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "outputs": [
    {
     "data": {
      "text/plain": "4.03"
     },
     "metadata": {},
     "output_type": "execute_result",
     "execution_count": 65
    }
   ],
   "source": [
    "# 这个是获取一个值\n",
    "lowest=stock_price.loc[stock_price.index[start_index:range_now],'low'].min()\n",
    "lowest"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "outputs": [
    {
     "data": {
      "text/plain": "             low  close  limit_up  limit_down  high  open  limit_line\ndate                                                                 \n2021-03-11  4.03   4.21       4.5        3.68   4.3  4.06           0",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>low</th>\n      <th>close</th>\n      <th>limit_up</th>\n      <th>limit_down</th>\n      <th>high</th>\n      <th>open</th>\n      <th>limit_line</th>\n    </tr>\n    <tr>\n      <th>date</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2021-03-11</th>\n      <td>4.03</td>\n      <td>4.21</td>\n      <td>4.5</td>\n      <td>3.68</td>\n      <td>4.3</td>\n      <td>4.06</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "output_type": "execute_result",
     "execution_count": 55
    }
   ],
   "source": [
    "# 进行了查询操作,\n",
    "lowest_line=stock_price[stock_price['low']==lowest]\n",
    "\n",
    "lowest_line"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "outputs": [
    {
     "data": {
      "text/plain": "             low  close  limit_up  limit_down  high  open  limit_line\ndate                                                                 \n2021-03-11  4.03   4.21       4.5        3.68   4.3  4.06           0",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>low</th>\n      <th>close</th>\n      <th>limit_up</th>\n      <th>limit_down</th>\n      <th>high</th>\n      <th>open</th>\n      <th>limit_line</th>\n    </tr>\n    <tr>\n      <th>date</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2021-03-11</th>\n      <td>4.03</td>\n      <td>4.21</td>\n      <td>4.5</td>\n      <td>3.68</td>\n      <td>4.3</td>\n      <td>4.06</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "output_type": "execute_result",
     "execution_count": 58
    }
   ],
   "source": [
    "# # 查询第二种方式\n",
    "# stock_price.query(f'low=={min}') \n",
    "# # 查询第三种方式\n",
    "# stock_price[stock_price['low'].isin([min])]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "outputs": [
    {
     "data": {
      "text/plain": "10.0"
     },
     "metadata": {},
     "output_type": "execute_result",
     "execution_count": 63
    }
   ],
   "source": [
    "# 查询到最高点\n",
    "\n",
    "highest=stock_price.loc[stock_price.index[start_index:range_now],'high'].max()\n",
    "highest"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "outputs": [
    {
     "data": {
      "text/plain": "             low  close  limit_up  limit_down  high  open  limit_line\ndate                                                                 \n2021-03-25  8.24   8.78     10.07        8.24  10.0   9.7           0",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>low</th>\n      <th>close</th>\n      <th>limit_up</th>\n      <th>limit_down</th>\n      <th>high</th>\n      <th>open</th>\n      <th>limit_line</th>\n    </tr>\n    <tr>\n      <th>date</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2021-03-25</th>\n      <td>8.24</td>\n      <td>8.78</td>\n      <td>10.07</td>\n      <td>8.24</td>\n      <td>10.0</td>\n      <td>9.7</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "output_type": "execute_result",
     "execution_count": 64
    }
   ],
   "source": [
    "# 查询最高点在的行\n",
    "highest_line=stock_price.query(f'high=={highest}')\n",
    "highest_line\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "outputs": [
    {
     "data": {
      "text/plain": "1.4813895781637716"
     },
     "metadata": {},
     "output_type": "execute_result",
     "execution_count": 66
    }
   ],
   "source": [
    "# 涨幅超过1\n",
    "rocket_rate=highest/lowest-1\n",
    "rocket_rate"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "source": [],
    "metadata": {
     "collapsed": false
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
